<?php

class McCube_Model /*implements McCube_Model_Interface*/{

    protected $_entity   = '';
    protected $_entities = array();

    /** */
    public function __construct($name, $bundle){
        $this->name       = $name;
        $this->bundle     = $bundle;
        $this->database   = $bundle->database;
    }

    /** */
    public function __get($name){
        return $this->getEntity($name);
    }

    /** */
    public function getEntity($name){
        if(!isset($this->_entities[$name]))
            $this->_entities[$name] = $this->bundle->getEntity($name);

        return $this->_entities[$name];
    }

    /** */
    public function getDatasByPair($table, $fieldForValue='name', $fieldForKey='id'){
        return $this->database->select()
            ->table   ($table)
            ->fields  ($fieldForKey.','.$fieldForValue)
            ->exec()
            ->setFetchMode(PDO::FETCH_KEY_PAIR)
            ->fetchArray()
        ;
    }


}